home *** CD-ROM | disk | FTP | other *** search
/ Power Programmierung 2 / Power-Programmierung CD 2 (Tewi)(1994).iso / c / library / dos / communic / pcmail / main / snapshot.c < prev    next >
Encoding:
C/C++ Source or Header  |  1994-06-05  |  2.8 KB  |  113 lines

  1. /*++
  2. /* NAME
  3. /*    snapshot 3
  4. /* SUMMARY
  5. /*    keep overview of the mail directory
  6. /* PROJECT
  7. /*    pc-mail
  8. /* PACKAGE
  9. /*    mail
  10. /* SYNOPSIS
  11. /*    #include "snapshot.h"
  12. /*
  13. /*    SNAP_SHOT *snap_shot(list)
  14. /*    char *list;
  15. /*
  16. /*    void snap_junk()
  17. /* DESCRIPTION
  18. /*      These functions maintain a "snapshot" of the mail directory;
  19. /*    this is a table of meta files.
  20. /*
  21. /*    snap_shot() make sure that a "snapshot" exists. list is
  22. /*    a null-terminated string of metafile suffix characters.
  23. /*    This function returns a list with as terminator an entry
  24. /*    with all zeros.
  25. /*
  26. /*    snap_junk() schedules a re-scan of the mail directory.
  27. /* FILES
  28. /*      mail header files in the spool directory
  29. /* BUGS
  30. /*      Since a message can be accessed only if its metafile exists,
  31. /*    a message is "lost" when for some reason the metafile is
  32. /*    not available.
  33. /* AUTHOR(S)
  34. /*      W.Z. Venema
  35. /*      Eindhoven University of Technology
  36. /*      Department of Mathematics and Computer Science
  37. /*      Den Dolech 2, P.O. Box 513, 5600 MB Eindhoven, The Netherlands
  38. /* CREATION DATE
  39. /*    Sun Dec 17 19:52:12 MET 1989
  40. /* LAST MODIFICATION
  41. /*    90/01/22 13:02:38
  42. /* VERSION/RELEASE
  43. /*    2.1
  44. /*--*/
  45.  
  46. #include <stdio.h>
  47.  
  48. #include "defs.h"
  49. #include "path.h"
  50. #include "ndir.h"
  51. #include "snapshot.h"
  52.  
  53. #define    SNAP_ALLOC    200        /* growth increment of table */
  54.  
  55. hidden SNAP_SHOT *snap_table = 0;    /* at most 16k messages on a PC */
  56. hidden int snap_used = 0;        /* nr of elements actually used */
  57. hidden int snap_length = 0;        /* actual length of table */
  58.  
  59. /* snap_add - add message to snapshot table */
  60.  
  61. hidden void snap_add(msgno, prefix)
  62. unsigned msgno;
  63. char    prefix;
  64. {
  65.     /* myrealloc() accepts a null pointer */
  66.  
  67.     if (snap_used >= snap_length) {
  68.     snap_length += SNAP_ALLOC;
  69.     if ((snap_table = (SNAP_SHOT *) myrealloc((char *) snap_table,
  70.                      snap_length * sizeof(snap_table))) == 0)
  71.         fatal("insufficient free memory for operation");
  72.     }
  73.     snap_table[snap_used].msgno = msgno;
  74.     snap_table[snap_used].prefix = prefix;
  75.     snap_used++;
  76. }
  77.  
  78. /* snap_build - record meta files in the mail directory */
  79.  
  80. hidden void snap_build(list)
  81. char   *list;
  82. {
  83.     DIR    *dp;                /* dir search id */
  84.     register struct direct *de;        /* directory entry */
  85.     unsigned msgno;            /* message sequence number */
  86.  
  87.     if (dp = opendir(maildir)) {
  88.     while (de = readdir(dp)) {
  89.         if ((msgno = seqno(de->d_name)) && strchr(list, de->d_name[0]) != 0)
  90.         snap_add(msgno, de->d_name[0]);
  91.     }
  92.     closedir(dp);
  93.     }
  94.     snap_add(0, 0);            /* add terminator */
  95. }
  96.  
  97. /* snap_junk - schedule re-build of snapshot table */
  98.  
  99. public void snap_junk()
  100. {
  101.     snap_used = 0;
  102. }
  103.  
  104. /* snap_shot - make sure snapshot table exists */
  105.  
  106. public SNAP_SHOT *snap_shot(list)
  107. char   *list;
  108. {
  109.     if (snap_used == 0)
  110.     snap_build(list);
  111.      return(snap_table);
  112. }
  113.